package bird.spring.com.designpattern.SuperImageLoader;

import android.graphics.Bitmap;

/**
 * Created by co-mall on 2015/12/7.
 * 双缓存机制，优先从内存加载，如果没有，则从SD卡加载
 * 保存时，两个地方都保存一下
 */
public class DoubleCache implements ImageCache {
    private DiskCache mDiskCache=new DiskCache();
    private MemoryCache mMemoryCache = new MemoryCache();

    @Override
    public Bitmap get(String url) {
        Bitmap bitmap = mMemoryCache.get(url);
        if (bitmap == null) {
            bitmap = mDiskCache.get(url);
        }

        return bitmap;
    }

    @Override
    public void put(String url, Bitmap bitmap) {
        mDiskCache.put(url, bitmap);
        mMemoryCache.put(url, bitmap);
    }
}
